package com.codegenerate.demo.dto;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.codegenerate.demo.config.R;
import com.codegenerate.demo.entity.GField;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.time.LocalDateTime;

public class GFieldDto implements Serializable {
    private long id;

    int pageNum;
    int pageSize;
    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public R validateUpdate(){
        if(this.getId()<0){
            return R.failed("id 不能为空");
        }
        return R.ok(null);
    }










    /**
     *
     */
    private String filedName;




    /**
     *
     */
    private String filedNameChinese;




    /**
     *
     */
    private String filedType;




    /**
     *
     */
    @JsonProperty(value = "gTableId")
    private long gTableId;




    /**
     *
     */
    private int delState;









    public long getId() {
        return id;
    }
    public void setId(long id) {
        this.id = id;
    }

    public String getFiledName() {
        return filedName;
    }
    public void setFiledName(String filedName) {
        this.filedName = filedName;
    }

    public String getFiledNameChinese() {
        return filedNameChinese;
    }
    public void setFiledNameChinese(String filedNameChinese) {
        this.filedNameChinese = filedNameChinese;
    }

    public String getFiledType() {
        return filedType;
    }
    public void setFiledType(String filedType) {
        this.filedType = filedType;
    }



    public int getDelState() {
        return delState;
    }
    public void setDelState(int delState) {
        this.delState = delState;
    }




    /**
     * build
     */
    public static GFieldDto build(){
        GFieldDto temp = new GFieldDto();



        temp.setId(0);

        temp.setFiledName("");

        temp.setFiledNameChinese("");

        temp.setFiledType("");

        temp.setgTableId(0);

        temp.setDelState(1);


        return temp;
    }

    public long getgTableId() {
        return gTableId;
    }

    public void setgTableId(long gTableId) {
        this.gTableId = gTableId;
    }

    /**
     * setDefaultValue
     */
    public void  setDefaultValue(GFieldDto temp){

        if(this.id<=0){
            temp.setId(0);
        }

        if(StringUtils.isEmpty(this.filedName)){
            temp.setFiledName("");
        }

        if(StringUtils.isEmpty(this.filedNameChinese)){
            temp.setFiledNameChinese("");
        }

        if(StringUtils.isEmpty(this.filedType)){
            temp.setFiledType("");
        }

        if(this.getgTableId()<=0){
            temp.setgTableId(0);
        }

        if(this.delState<=0){
            temp.setDelState(1);
        }

    }



    /**
     * dto2entity
     */
    public GField dto2entity(){
        var entity=GField.build();

        if(this.id>0){
            entity.setId(this.getId());
        }

        if(!StringUtils.isEmpty(this.filedName)){
            entity.setFiledName(this.getFiledName());
        }

        if(!StringUtils.isEmpty(this.filedNameChinese)){
            entity.setFiledNameChinese(this.getFiledNameChinese());
        }

        if(!StringUtils.isEmpty(this.filedType)){
            entity.setFiledType(this.getFiledType());
        }

        if(this.gTableId>0){
            entity.setgTableId(this.getgTableId());
        }

        if(this.delState>0){
            entity.setDelState(this.getDelState());
        }

        return entity;
    }



    public Page<GField> buildPage(){
        Page<GField> tempage = new Page<GField>();
        tempage.setCurrent(this.getPageNum()<=0?0:this.getPageNum());
        tempage.setSize(this.getPageSize()<=0?10:this.getPageSize());
        return tempage;
    }


}